package controle;

import java.io.*;
//import java.net.*;

import javax.servlet.*;
import javax.servlet.http.*;



import modelo.Conexao;

public class ServletWeb extends HttpServlet {
    private ServletContext sc;
    private String jsp = "";
    
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
        sc = config.getServletContext();
        Conexao.conectar(sc.getInitParameter("url"), sc.getInitParameter("usuario"),
                sc.getInitParameter("senha"), sc.getInitParameter("driver"));
    }
    
    
    /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     */
    protected void service(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        String acao = request.getParameter("acao");
        
        if(acao.equals("Logar"))            
            jsp = Login.execute(request);
       
        //Redirecionando pagina
        RequestDispatcher rd = request.getRequestDispatcher(jsp);
        rd.forward(request, response);
    }
    
    public void destroy() {
        Conexao.destroy();
    }
}
